package com.gx.mxbbx.controller;

import com.github.pagehelper.PageInfo;
import com.gx.mxbbx.po.Rural;
import com.gx.mxbbx.po.SysUser;
import com.gx.mxbbx.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @RequestMapping("/getpaymentList")
    public String getpaymentList(Integer currentPage, Integer limit, HttpServletRequest request, Model model) {
        String fullName = request.getParameter("context");
        currentPage = currentPage != null ? currentPage : 1;
        limit = limit != null ? limit : 10;
        PageInfo<Rural> pageInfo = paymentService.getruralList(fullName, currentPage, limit);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("context", fullName);
        return "/payment/payment_list";
    }

    @RequestMapping("/ruralpayment")
    public String ruralpayment(String familyId, Integer currentPage, Integer limit, Model model, HttpSession session) {
        currentPage = currentPage != null ? currentPage : 1;
        limit = limit != null ? limit : 10;
        PageInfo<Rural> pageInfo = paymentService.ruralpayment(familyId, currentPage, limit);
        SysUser sysUser = (SysUser) session.getAttribute("sysUser");
        model.addAttribute("sysUser", sysUser);
        model.addAttribute("pageInfo", pageInfo);
        return "/payment/payment";
    }

    //打印缴费单未完成
    @RequestMapping("/payment")
    public String payment(HttpServletRequest request, Model model) {
        String[] ids = request.getParameterValues("ids");
        return getpaymentList(1, 10, request, model);
    }
}
